package com.example.first;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyAdapter extends ArrayAdapter{
    public MyAdapter(@NonNull Context context, int resource, List<HashMap<String,String>> list) {
        super(context, resource, list);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View itemview = convertView;
        if(itemview == null){
            itemview = LayoutInflater.from(getContext()).inflate(R.layout.list_item,parent,false);
        }
        Map<String,String> map = (Map<String,String>)getItem(position);
        TextView title = itemview.findViewById(R.id.title1);
        TextView detail = itemview.findViewById(R.id.detail);
        title.setText("币种:"+map.get("cname"));
        detail.setText("汇率:"+map.get("cval"));
        return itemview;
    }
}
